<?php



namespace App\Services\Business\Models;


use App\Services\Business\Models\Appraise;
use App\Services\Business\Models\MediaImage;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Product extends Model
{
    use SoftDeletes,HasFactory;

    protected $table = 'product';

    protected $fillable = [
        'user_id','thumb', 'title','point','stock','charge','description','video_id'
    ];
    public function images()
    {
        return $this->morphMany(MediaImage::class, 'media_imageable');
    }
    public function mediaVideo()
    {
        return $this->morphToMany(MediaVideo::class, 'media_videoable');
    }

    public function mediaImages()
    {
        return $this->morphToMany(MediaImage::class, 'media_imageable');
    }
    public function video()
    {
        return $this->belongsTo(Video::class, 'video_id');
    }

    public function appraises()
    {
        return $this->morphMany(Appraise::class, 'appraiseable')->with(['user:id,nick_name,avatar']);
    }

}
